/*
 * Copyright (c) 2010-2011 NOO. All Rights Reserved.
 * [Id:QueryField.java  2011-10-28 上午1:26 poplar.yfyang ]
 */
package org.mumu.pawn.fm.util;

import java.io.Serializable;

/**
 * <p>
 * JPA查询属性，用来构建到基本的查询积累中.
 * </p>
 *
 * @author poplar.yfyang
 * @version 1.0 2011-10-28 上午1:26
 * @since JDK 1.5
 */
public class QueryField implements Serializable {
    private static final long serialVersionUID = -1486208719842216838L;
    /**
     * 字段名称
     */
    private String fieldName;

    /**
     * 字段对应值
     */
    private Object fieldValue;

    /**
     * 查询匹配规则
     */
    private QUERYTYPE querytype;

    /**
     * 构造器
     *
     * @param fieldName  字段名称
     * @param fieldValue 字段值
     * @param querytype  查询方式
     */
    public QueryField(String fieldName, Object fieldValue, QUERYTYPE querytype) {
        this.fieldName = fieldName;
        this.fieldValue = fieldValue;
        this.querytype = querytype;
    }

    /**
     * 取得查询字段名称
     *
     * @return 查询字段名称
     */
    public String getFieldName() {
        return fieldName;
    }

    /**
     * 查询字段值
     *
     * @return 查询字段值
     */
    public Object getFieldValue() {
        return fieldValue;
    }

    /**
     * 查询类型
     *
     * @return 查询类型
     */
    public QUERYTYPE getQuerytype() {
        return querytype;
    }

    /**
     * 查询类别
     */
    public enum QUERYTYPE {
        /**
         * AND查询
         *
         * @see {@link javax.persistence.criteria.CriteriaBuilder#and(javax.persistence.criteria.Predicate...)}
         */
        AND,
        /**
         * OR查询
         *
         * @see {@link javax.persistence.criteria.CriteriaBuilder#or(javax.persistence.criteria.Predicate...)}
         */
        OR,
        /**
         * 限定字段值
         *
         * @see {@link javax.persistence.criteria.CriteriaBuilder#not(javax.persistence.criteria.Expression)}
         */
        NOT,
        /**
         * 是否存在
         *
         * @see {@link javax.persistence.criteria.CriteriaBuilder#exists(javax.persistence.criteria.Subquery)}
         */
        EXIST,
        /**
         * @see {@link javax.persistence.criteria.CriteriaBuilder#equal(javax.persistence.criteria.Expression, Object)} )}
         */
        EQUAL,
        /**
         * @see {@link javax.persistence.criteria.CriteriaBuilder#notEqual(javax.persistence.criteria.Expression, Object)}
         */
        NOTEQUAL,
        /**
         * @see {@link javax.persistence.criteria.CriteriaBuilder#like(javax.persistence.criteria.Expression, String)}
         */
        LIKE,
        /**
         * @see {@link javax.persistence.criteria.CriteriaBuilder#notLike(javax.persistence.criteria.Expression, String)}
         */
        NOTLIKE
    }
}
